package mytest.huaweiG.GraphB;

import java.util.Map;
import java.util.Set;

import static GraphB.TimeRecorder.topologicalSort;

/**
 * Created by safe on 2017-04-01.
 */
public class Test {
    public static void main(String[] args) {
        Graph graph = new Graph();
        Set<Vertex> vertexSet = graph.getVertexSet();
        Map<Vertex, Vertex[]> edgeMap = graph.getAdjacencys();

        Vertex twoVertex = new Vertex("2");
        Vertex threeVertex = new Vertex("3");
        Vertex fiveVertex = new Vertex("5");
        Vertex sevenVertex = new Vertex("7");
        Vertex eightVertex = new Vertex("8");
        Vertex nineVertex = new Vertex("9");
        Vertex tenVertex = new Vertex("10");
        Vertex elevenVertex = new Vertex("11");

        vertexSet.add(twoVertex);
        vertexSet.add(threeVertex);
        vertexSet.add(fiveVertex);
        vertexSet.add(sevenVertex);
        vertexSet.add(eightVertex);
        vertexSet.add(nineVertex);
        vertexSet.add(tenVertex);
        vertexSet.add(elevenVertex);

        edgeMap.put(twoVertex, new Vertex[] { elevenVertex });
        edgeMap.put(nineVertex, new Vertex[] { elevenVertex, eightVertex });
        edgeMap.put(tenVertex, new Vertex[] { elevenVertex, threeVertex });
        edgeMap.put(elevenVertex, new Vertex[] { sevenVertex, fiveVertex });
        edgeMap.put(eightVertex, new Vertex[] { sevenVertex, threeVertex });

        Vertex[] sortedVertexs = topologicalSort(graph);
        printVertex(sortedVertexs);
    }

    public static void printVertex(Vertex[] Vertexs) {
        for (Vertex vertex : Vertexs) {
            System.out.println(vertex.getName() + "  discover time:"
                    + vertex.getDiscover() + "  finish time:"
                    + vertex.getFinish());
        }
    }
}
